﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using NorthWind;

namespace td.Core
{
    public partial class userControl : XtraUserControl
    {
        
        public userControl()
        {
            InitializeComponent();
            WorkBenchSingleTon.WorkBench.TabPageAdded += new EventHandler(WorkBench_TabPageAdded);
            WorkBenchSingleTon.WorkBench.TabPageClosing += new EventHandler(WorkBench_TabPageClosing);

        }

        void WorkBench_TabPageClosing(object sender, EventArgs e)
        {
            var p = sender as IViewContent;
            if (p.Title == "Customers")
            {
                WorkBenchSingleTon.WorkBench.TabPageAdded -= new EventHandler(WorkBench_TabPageAdded);
                ((NorthWind.NortWindControl)(p).ViewContentControl).SelectedRowChanged -= new EventHandler(userControl_SelectedRowChanged);

            }
        }

        void WorkBench_TabPageAdded(object sender, EventArgs e)
        {
            var p = sender as IViewContent;
            if (p.Title == "Customers")
            {
                WorkBenchSingleTon.WorkBench.TabPageAdded += new EventHandler(WorkBench_TabPageAdded);
                ((NorthWind.NortWindControl)(p).ViewContentControl).SelectedRowChanged += new EventHandler(userControl_SelectedRowChanged);

            }
        }

        void userControl_SelectedRowChanged(object sender, EventArgs e)
        {
            
            this.propertyGrid1.SelectedObject = /*(Customers)*/(sender);
            var pad = WorkBenchSingleTon.WorkBench.GetPad("测试");
            if (pad != null)
            {
                pad.Show();
            }
        }
    }
}
